<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="/admin/plugins/layui/css/layui.css" media="all"
			/>
		<link rel="stylesheet" href="/admin/css/main.css" />
		<style>
			.layui-form-label{
				width: 70px;
			}
			.layui-input-block{
				max-width: 800px;
			}
		</style>
		<!--多文本编辑器-->
		<script type="text/javascript" charset="utf-8"
			src="/ueditor/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8"
			src="/ueditor/ueditor.all.min.js"> </script>
		<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
		<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
		<script type="text/javascript" charset="utf-8"
			src="/ueditor/lang/zh-cn/zh-cn.js"></script>
		<!--多文本编辑器-->
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top:
				20px;">
				<legend>添加产品</legend>
			</fieldset>
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">产品编号</label>
					<div class="layui-input-inline" style="width:260px;">
						<input type="text" id="productNo" name="productNo" autocomplete="off"
							placeholder="如：88-西安市长安区-床+床头柜1" class="layui-input">
					</div>
					<label class="layui-form-label">排序</label>
					<div class="layui-input-inline">
						<input type="text" id="order" name="order" autocomplete="off"
							placeholder="数值越大，越靠前（可选）" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">产品标题</label>
					<div class="layui-input-block">
						<input type="text" id="title" name="title" autocomplete="off"
							placeholder="请输入产品名称" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">方米立货号</label>
					<div class="layui-input-block" style="width:260px;">
						<input type="text" id="waybillId" name="waybillId" autocomplete="off"
							placeholder="请输入运单号（可选）" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">产品类别</label>
					<div class="layui-input-inline" style="width:260px;">
						<select name="category" class="layui-input" id="category">
							<option value="factory">工厂产品</option>
							<option value="family">饭团产品</option>
							<option value="promote">促销产品</option>
							<option value="special">特价福利</option>
						</select>
					</div>
					<label class="layui-form-label">产品状态</label>
					<div class="layui-input-inline" style="width:260px;">
						<select name="status" class="layui-input" id="status">
							<option value="0">待出售</option>
							<option value="1">已出售</option>
							<option value="2">暂不出售</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">提供日期</label>
					<div class="layui-input-block" style="width:260px;">
						<input type="text" id="time" name="time" id="date"
							placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input"
							onclick="layui.laydate({elem: this})">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">货物情况</label>
					<div class="layui-input-block">
						<input type="text" id="description" name="description" autocomplete="off"
							placeholder="货物情况描述（可选）" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">价格</label>
					<div class="layui-input-inline">
						<input type="text" id="price" name="price" autocomplete="off"
							placeholder="饭团价/促销价/福利价" class="layui-input">
					</div>
					<label class="layui-form-label">网上原价</label>
					<div class="layui-input-inline">
						<input type="text" id="shopPrice" name="shopPrice" autocomplete="off"
							placeholder="网上价格（可选，默认为0）" class="layui-input">
					</div>
					<label class="layui-form-label">参考价</label>
					<div class="layui-input-inline">
						<input type="text" id="refPrice" name="refPrice" autocomplete="off"
							placeholder="推荐价格" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">产品链接</label>
					<div class="layui-input-block">
						<input type="text" id="from" name="from" autocomplete="off"
							placeholder="网上产品链接（可选）" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">编辑内容</label>
					<div class="layui-input-block">
						<script id="editor" type="text/plain" style="width:900px;height:700px;"></script>
						<!--<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>-->
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" id="add">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="/admin/plugins/layui/layui.js"></script>
		<script>
		layui.use(['form', 'laydate','upload'], function() {
			var form = layui.form(),
					layer = layui.layer,
					laydate = layui.laydate,
					$= layui.jquery;

			var ue = UE.getEditor('editor');
			//监听提交
			//点击添加分类
			$('#add').on('click', function($event) {
				$event.preventDefault();
				var title=$("#title").val();
				var time=$("#time").val();
				var from=$("#from").val();
				var waybillId=$("#waybillId").val();
				var description=$("#description").val();
				var productNo=$("#productNo").val();
				var price=$("#price").val() || 0;
				var order=$("#order").val() || 1;
				var refPrice=$("#refPrice").val() || 0;
				var shopPrice=$("#shopPrice").val() || 0;
				var category=$('#category').val();
				var status=$('#status').val();
				//获取多文本编辑内容
				var content=UE.getEditor('editor').getContent();
				//测试用户是否录入信息
				if(title=="" || time==""){
					layer.alert('请填入标题或者产品提供日期', {icon: 2});
					return;
				}
				if(productNo==""){
					layer.alert("请输入产品编号",{icon:2});
					return;
				}
				if(price==""){
					layer.alert("请输入价格",{icon:2});
					return;
				}
				/*alert("title"+title+"time"+time+"from"+from+"from"+imgurl+"content"+content);*/
				$.post("/admin/add_products",{
					productNo: productNo,
					title:title,
					time:time, 
					refPrice: refPrice, 
					shopPrice: shopPrice, 
					order: order, 
					waybillId: waybillId,
					 description: description,
					 from:from,
					 category:category,
					 status: status,
					 content:content
					},function(result){
					if(result.status==="success"){
						layer.alert('添加成功,请在产品列表查看。', {icon: 1});
					}else{
						layer.alert('添加失败', {icon: 2});
					}
				});
				//这句话的意思不会刷新当前页面。避免清空内容
				return false;
			});
		});
	</script>
	</body>

</html>